package com.offcn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.offcn.bean.Evaluate;
import com.offcn.bean.EvaluateExample;
import com.offcn.mapper.EvaluateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluateServiceImpl implements EvaluateService{
    @Autowired
    private EvaluateMapper evaluateMapper;

    @Override
    public PageInfo<Evaluate> getEvaluate(Integer bid, Integer pageNo,String econtent) {
        PageHelper.startPage(pageNo,3);
        EvaluateExample evaluateExample = new EvaluateExample();
        evaluateExample.setOrderByClause("etime desc");
        if(bid == -1){
            //查询所有的评论
            evaluateExample.createCriteria().andEcontentLike("%"+econtent+"%");
            List<Evaluate> evaluates = evaluateMapper.selectByExample(evaluateExample);
            return new PageInfo<Evaluate>(evaluates,4);

        }else{
            //查看博客详情下的查看评论
            evaluateExample.createCriteria().andBFkEqualTo(bid);
            List<Evaluate> evaluates = evaluateMapper.selectByExample(evaluateExample);
            PageInfo<Evaluate> evaluatePageInfo = new PageInfo<>(evaluates, 4);
            return evaluatePageInfo;
        }

    }

    @Override
    public void deleteComment(Integer eid) {
        int i = evaluateMapper.deleteByPrimaryKey(eid);
    }

    @Override
    public void addEvaluate(Evaluate evaluate) {
        int insert = evaluateMapper.insert(evaluate);
    }
}
